home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / system-config-printer / troubleshoot / CheckPPDSanity.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  6KB  |  157 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import cups
  5. import cupshelpers
  6. import installpackage
  7. import os
  8. import subprocess
  9. from timedops import TimedOperation, TimedSubprocess
  10. from base import *
  11.  
  12. class CheckPPDSanity(Question):
  13.     
  14.     def __init__(self, troubleshooter):
  15.         Question.__init__(self, troubleshooter, 'Check PPD sanity')
  16.         vbox = gtk.VBox()
  17.         vbox.set_border_width(12)
  18.         vbox.set_spacing(12)
  19.         self.label = gtk.Label()
  20.         self.label.set_line_wrap(True)
  21.         self.label.set_use_markup(True)
  22.         self.label.set_alignment(0, 0)
  23.         vbox.pack_start(self.label, False, False, 0)
  24.         box = gtk.HButtonBox()
  25.         box.set_layout(gtk.BUTTONBOX_START)
  26.         self.install_button = gtk.Button(_('Install'))
  27.         box.add(self.install_button)
  28.         vbox.pack_start(box, False, False, 0)
  29.         troubleshooter.new_page(vbox, self)
  30.  
  31.     
  32.     def display(self):
  33.         self.answers = { }
  34.         answers = self.troubleshooter.answers
  35.         if not answers['cups_queue_listed']:
  36.             return False
  37.         parent = self.troubleshooter.get_window()
  38.         name = answers['cups_queue']
  39.         tmpf = None
  40.         
  41.         try:
  42.             cups.setServer('')
  43.             self.op = TimedOperation(cups.Connection, parent = parent)
  44.             c = self.op.run()
  45.             self.op = TimedOperation(c.getPPD, args = (name,), parent = parent)
  46.             tmpf = self.op.run()
  47.         except RuntimeError:
  48.             answers['cups_queue_listed']
  49.             answers['cups_queue_listed']
  50.             return False
  51.             except cups.IPPError:
  52.                 return False
  53.             else:
  54.                 self.install_button.hide()
  55.                 title = None
  56.                 text = None
  57.                 
  58.                 try:
  59.                     ppd = cups.PPD(tmpf)
  60.                     self.answers['cups_printer_ppd_valid'] = True
  61.                     
  62.                     def options(options_list):
  63.                         o = { }
  64.                         for option in options_list:
  65.                             o[option.keyword] = option.defchoice
  66.                         
  67.                         return o
  68.  
  69.                     defaults = { }
  70.                     for group in ppd.optionGroups:
  71.                         g = options(group.options)
  72.                         for subgroup in group.subgroups:
  73.                             g[subgroup.name] = options(subgroup.options)
  74.                         
  75.                         defaults[group.name] = g
  76.                     
  77.                     self.answers['cups_printer_ppd_defaults'] = defaults
  78.                 except RuntimeError:
  79.                     title = _('Invalid PPD File')
  80.                     self.answers['cups_printer_ppd_valid'] = False
  81.                     
  82.                     try:
  83.                         self.op = TimedSubprocess(parent = parent, args = [
  84.                             'cupstestppd',
  85.                             '-rvv',
  86.                             tmpf], stdin = file('/dev/null'), stdout = subprocess.PIPE, stderr = subprocess.PIPE)
  87.                         result = self.op.run()
  88.                         self.answers['cupstestppd_output'] = result
  89.                         text = _("The PPD file for printer '%s' does not conform to the specification.  Possible reason follows:") % name
  90.                         text += '\n' + reduce((lambda x, y: x + '\n' + y), result[0])
  91.                     except OSError:
  92.                         text = _("There is a problem with the PPD file for printer '%s'.") % name
  93.                     except:
  94.                         None<EXCEPTION MATCH>OSError
  95.                     
  96.  
  97.                     None<EXCEPTION MATCH>OSError
  98.  
  99.                 if tmpf:
  100.                     os.unlink(tmpf)
  101.                 
  102.  
  103.         if title == None and not answers['cups_printer_remote']:
  104.             (pkgs, exes) = cupshelpers.missingPackagesAndExecutables(ppd)
  105.             self.answers['missing_pkgs_and_exes'] = (pkgs, exes)
  106.             if len(pkgs) > 0 or len(exes) > 0:
  107.                 title = _('Missing Printer Driver')
  108.                 if len(pkgs) > 0:
  109.                     
  110.                     try:
  111.                         self.packagekit = installpackage.PackageKit()
  112.                     pkgs = []
  113.  
  114.                 
  115.                 if len(pkgs) > 0:
  116.                     self.package = pkgs[0]
  117.                     text = _("Printer '%s' requires the %s package but it is not currently installed.") % (name, self.package)
  118.                     self.install_button.show()
  119.                 else:
  120.                     text = _("Printer '%s' requires the '%s' program but it is not currently installed.") % (name, exes + pkgs[0])
  121.             
  122.         
  123.         if title != None:
  124.             self.label.set_markup('<span weight="bold" size="larger">' + title + '</span>\n\n' + text)
  125.         
  126.         return title != None
  127.  
  128.     
  129.     def connect_signals(self, handle):
  130.         self.button_sigid = self.install_button.connect('clicked', self.install_clicked)
  131.  
  132.     
  133.     def disconnect_signals(self):
  134.         self.install_button.disconnect(self.button_sigid)
  135.  
  136.     
  137.     def collect_answer(self):
  138.         return self.answers
  139.  
  140.     
  141.     def cancel_operation(self):
  142.         self.op.cancel()
  143.  
  144.     
  145.     def install_clicked(self, button):
  146.         pkgs = self.answers.get('packages_installed', [])
  147.         pkgs.append(self.package)
  148.         self.answers['packages_installed'] = pkgs
  149.         
  150.         try:
  151.             self.packagekit.InstallPackageName(0, 0, self.package)
  152.         except:
  153.             pass
  154.  
  155.  
  156.  
  157.